This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# Verificamos la ruta donde se encuentra el archivo
getwd()
## [1] "/home/alejo/Documentos/lab2"
datos<-read.csv("demandaBicis.csv", T, ",", encoding = "UTF-8")
head(datos)
## instant dteday season yr mnth hr holiday weekday workingday
## 1 1 2011-01-01 1 0 1 0 0 6 0
## 2 2 2011-01-01 1 0 1 1 0 6 0
## 3 3 2011-01-01 1 0 1 2 0 6 0
## 4 4 2011-01-01 1 0 1 3 0 6 0
## 5 5 2011-01-01 1 0 1 4 0 6 0
## 6 6 2011-01-01 1 0 1 5 0 6 0
## weathersit temp atemp hum windspeed casual registered cnt
## 1 1 0.24 0.2879 0.81 0.0000 3 13 16
## 2 1 0.22 0.2727 0.80 0.0000 8 32 40
## 3 1 0.22 0.2727 0.80 0.0000 5 27 32
## 4 1 0.24 0.2879 0.75 0.0000 3 10 13
## 5 1 0.24 0.2879 0.75 0.0000 0 1 1
## 6 2 0.24 0.2576 0.75 0.0896 0 1 1
```
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Pregunta No. 1
¿Que mes es el que tiene la mayor demanda?
pregunta1<-datos%>%
select(mnth,cnt)%>%
group_by(mnth)%>%
summarise(sumpreg1=sum(cnt))%>%
arrange(desc(sumpreg1))
head(pregunta1)
## # A tibble: 6 x 2
## mnth sumpreg1
## <int> <int>
## 1 8 351194
## 2 6 346342
## 3 9 345991
## 4 7 344948
## 5 5 331686
## 6 10 322352
Respuesta: El mes con mayor demanda es agosto.
Pregunta No. 2 Que rango de hora es la de mayor demanda?
pregunta2<-datos%>%
select(hr,cnt)%>%
group_by(hr)%>%
summarise(sumpreg2=sum(cnt))%>%
arrange(desc(sumpreg2))
head(pregunta2)
## # A tibble: 6 x 2
## hr sumpreg2
## <int> <int>
## 1 17 336860
## 2 18 309772
## 3 8 261001
## 4 16 227748
## 5 19 226789
## 6 13 184919
La hora con mayor demanda es 17:00 horas.
Pregunta No. 3 Que temporada es la mas alta?
pregunta3<-datos%>%
select(season,cnt)%>%
group_by(season)%>%
summarise(sumpreg3=sum(cnt))%>%
arrange(desc(sumpreg3))
head(pregunta3)
## # A tibble: 4 x 2
## season sumpreg3
## <int> <int>
## 1 3 1061129
## 2 2 918589
## 3 4 841613
## 4 1 471348
La temporada mas alta es en otoño
Pregunta No. 4 A que temperatura baja la demanda?
pregunta4<-datos%>%
select(temp,cnt)%>%
group_by(temp)%>%
summarise(sumpreg4=sum(cnt))%>%
arrange(sumpreg4)
head(pregunta4)
## # A tibble: 6 x 2
## temp sumpreg4
## <dbl> <int>
## 1 1 294
## 2 0.08 480
## 3 0.98 539
## 4 0.04 570
## 5 0.06 672
## 6 0.02 712
La temperatura de menor demanda es 100 grados.
Pregunta No. 5 A que humedad baja la demanda?
pregunta5<-datos%>%
select(hum,cnt)%>%
group_by(hum)%>%
summarise(sumpreg5=sum(cnt))%>%
arrange(sumpreg5)
head(pregunta5)
## # A tibble: 6 x 2
## hum sumpreg5
## <dbl> <int>
## 1 0.13 17
## 2 0.12 29
## 3 0.14 38
## 4 0.97 64
## 5 0.08 77
## 6 0.1 107
La humedad de menor demanda es 13%. En temporadas secas y calurosas baja la demanda del servicio de bicicletas.
Pregunta No. 6 Condiciones ideales
c(pregunta1[1,1],pregunta2[1,1],pregunta3[1,1],pregunta4[6,1],pregunta5[6,1])
## $mnth
## [1] 8
##
## $hr
## [1] 17
##
## $season
## [1] 3
##
## $temp
## [1] 0.02
##
## $hum
## [1] 0.1
Pregunta No. 7 Grafica de la densidad de temperatura
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
pregunta7<-plot_ly(x=datos$temp,type = "histogram")
pregunta7
Pregunta No. 8 Con una gr?fica explique en que temporada hubieron mas rentas de bicicletas.
pregunta8<-plot_ly(x=pregunta3$season,y=pregunta3$sumpreg3,type = "bar")
pregunta8
Pregunta No. 9
preg9<-datos%>%
select(season, cnt)
head(preg9)
## season cnt
## 1 1 16
## 2 1 40
## 3 1 32
## 4 1 13
## 5 1 1
## 6 1 1
Pregunta No. 10
preg10<-datos%>%
select(weekday, casual, registered) %>%
group_by(weekday)
head(preg10)
## # A tibble: 6 x 3
## # Groups: weekday [1]
## weekday casual registered
## <int> <int> <int>
## 1 6 3 13
## 2 6 8 32
## 3 6 5 27
## 4 6 3 10
## 5 6 0 1
## 6 6 0 1
pregunta10<-plot_ly(preg10, x = preg10$weekday, y = preg10$registered, type = 'bar', name = 'Registered') %>%
add_trace(y = preg10$casual, name = 'Casual') %>%
layout(yaxis = list(title = 'Count'), barmode = 'stack')
pregunta10